﻿@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        var opts = {
            rows: 15,
            height: 450,
            url: "/SysUser/GetList",
            para: {},
            idField: "Guid",
            columns: [
                    { field: 'EmployeeName', title: '姓名', width: 10, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            return "<a href='#' onclick='View(\"" + rowData.Guid + "\")'>" + value + "</a>";
                        }
                    },
                    { field: 'Username', title: '用户名', width: 10, sortable: true },
                    { field: 'Gender', title: '性别', width: 5, align: 'center', sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            if (value == 1)
                                return "男";
                            else
                                return "女";
                        }
                    },
                    { field: 'CompanyName', title: '公司', width: 35, sortable: true },
                    { field: 'OfficeTel', title: '办工电话', width: 12, sortable: true },
                    { field: 'OfficeEmail', title: 'Email', width: 18, sortable: true },
                    { field: 'Guid', title: '操作', width: 10, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var a = "<select onchange='DoAction(this.options.selectedIndex,\"" + value + "\")' style='width: 80px; '><option value=''>-请选择-</option>";
                            if (rowData.Username == "SuperAdmin") {
                                return a + "<option>修改</option></select>";
                            } else
                                return a + "<option>修改</option><option>删除</option></select>";
                        }
                    }
                    ]
        };
        $(function () {
            $("#DataGrid").dg(opts);
        });
        function View(id) {
            showModalMany('Contact', "/SysUser/Read?id=" + id, '520', '300', "off");
        }
        function btnSearch() {
            opts.para["UserType"] = $("#txt_UserType").val();
            opts.para["EmployeeName"] = $.trim($("#txt_EmployeeName").val());
            opts.para["UserName"] = $.trim($("#txt_UserName").val());
            thisPageNum = 1;
            $("#DataGrid").dg(opts);
        }
        function DoAction(i, value) {
            if (i == 1) {
                EditItem(value);
            }
            else {
                DeleteItem(value);
            }
        }
        function EditItem(v) {
            window.location.href = "/SysUser/Edit/?userID=" + v;
        } 
        function DeleteItem(v) {
            if (confirm("确定要删除吗？")) {
                $.post("/SysUser/DeleteItem/?id=" + v, function (result) {
                    if (result == 1) {
                        alert("删除成功！"); 
                    } else if (result == 2) {
                        alert("已为该人员配置角色不能删除！");
                    } else {
                        alert("删除失败！");
                    }
                    $("#DataGrid").dg(opts);
                });
            } else
                $("#DataGrid").dg(opts);
        }
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                用户列表搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                姓名：
                <input type="text" id="txt_EmployeeName" />
                用户名：
                <input type="text" id="txt_UserName" />
                <input type="button" value="搜索" class="button" onclick="btnSearch()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                用户列表<span id="type_Name"></span>
            </td>
            <td align="right">
            <input type="button" class="button" value="添加" onclick="EditItem('')"/>
            </td>
        </tr>
    </table>
    <table id="DataGrid" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
 
